package com.jse.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.jse.log.Logs;

public class Times extends com.jse.lang.Times {

	public static String format(String pattern, Date time) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(time);
	}

	public static String format(Date time) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(time);
	}

	public static String format() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date());
	}

	public static Date parse(String str) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = format.parse(str);
		} catch (ParseException e) {
			try {
				date=new SimpleDateFormat("yyyy-MM-dd").parse(str);
			} catch (ParseException e1) {
				e1.printStackTrace();
			}
		}
		return date;
	}

	/**
	 * 增加天数
	 * 
	 * @param date
	 * @param num
	 * @return
	 */
	public static Date addDay(Date date, int num) {
		Calendar startDT = Calendar.getInstance();
		startDT.setTime(date);
		startDT.add(Calendar.DAY_OF_MONTH, num);
		return startDT.getTime();
	}

	/**
	 * 明天当前时间
	 * 
	 * @return
	 */
	public static Date tomorrow() {
		Calendar startDT = Calendar.getInstance();
		startDT.add(Calendar.DAY_OF_MONTH, 1);
		return startDT.getTime();
	}
	
	public static Date day(String str) {
		Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
        try {
        	String[] hms=str.split(":");
    		int hh=Integer.parseInt(hms[0]);
    		int mm=Integer.parseInt(hms[1]);
    		int ss=Integer.parseInt(hms[2]);
    		calendar.set(year, month, day, hh, mm, ss);
		} catch (Exception e) {
			Logs.get().warn("HH:mm:ss to Date err:%s", e);
		}
        return calendar.getTime();
	}

	public static void main(String[] args) throws ParseException {
		System.err.println(day("23:12:11"));
	}

	public static Date now() {
		return new Date();
	}
}
